/**
 * 作者I-AM-WASTE
 * TIME:2022,10,10
 */

let b = new Vue({
    el:"#nav-box",
    data:{
        navflag:false,
        flag:true,
        nightFlag:false,
        timeh:null,
        newHour:0,
        scrollTop:0
    },
    methods:{
        windowScrolls(){
            this.scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
            if (this.scrollTop >= 475){
                this.navflag = true
            }else {
                this.navflag = false
            }
        },
        windowScroll(){
            this.scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
        },
        navclick(){
            if (this.flag){
                window.removeEventListener("scroll",this.windowScrolls)
                window.addEventListener("scroll",this.windowScroll)
                this.navflag = false
                this.flag = !this.flag
            }else {
                window.addEventListener("scroll",this.windowScrolls)
                if (this.scrollTop >= 475){
                    this.navflag = true
                }else {
                    this.navflag = false
                }
                this.flag = !this.flag
            }
        },
        settingreset(){
            this.flag = false
            window.removeEventListener("scroll",this.windowScrolls)
            window.addEventListener("scroll",this.windowScroll)
            this.navflag = false

            this.nightFlag = false
        },

    },
    mounted(){
        window.addEventListener("scroll",this.windowScrolls)

    },
    beforeDestroy(){
        window.removeEventListener("scroll",this.windowScrolls)
        window.removeEventListener("scroll",this.windowScroll)
        this.navflag = false
        this.flag = !this.flag
        clearInterval(this.timeh)
    }
})


function setting(){
    let setting = document.getElementById('set-all')
    let svg = document.getElementById('rotate-svg')
    if (setting.classList.contains('active')) {
        setting.classList.remove('active')
        setting.classList.remove('setting-open')
        setting.classList.add('setting-close')
        clearInterval(rotate.time)
    } else {
        setting.classList.add('active')
        setting.classList.remove('setting-close')
        setting.classList.add('setting-open')
        rotate(svg,180,10)
    }
}

//旋转
function rotate(obj,direction,speed){//对象，方向，速度，
    var rotateVal=0
    var dir=direction!==undefined?direction:true
    var spe=speed||0.1
    rotate.time = setInterval(function() {
        rotateVal += 1;
        obj.style.transform = 'rotateZ('+(dir?"+":"-") + rotateVal+ 'deg)';
        if(rotateVal>360)
            rotateVal=0
    },0)
}

function backclick(){
    document.documentElement.scrollTop = 0;
}

let year = document.getElementById("newyear")
year.innerText = ""+new Date().getFullYear()+""
